package org.domeos.framework.api.model.ci.related;

import org.apache.commons.lang3.StringUtils;
import org.domeos.basemodel.ResultStat;
import org.domeos.framework.api.controller.exception.ApiException;
import org.domeos.framework.api.model.project.Project;
import org.domeos.util.CommonUtil;

/**
 * Created by feiliu206363 on 2016/4/4.
 */
public class ImageInformation {
    private String registry;
    private String imageName;
    private String imageTag;
    private double imageSize;

    public String getRegistry() {
        return registry;
    }

    public void setRegistry(String registry) {
        this.registry = registry;
    }

    public String getImageName() {
        return imageName;
    }

    public void setImageName(String imageName) {
        this.imageName = imageName;
    }

    public String getImageTag() {
        return imageTag;
    }

    public void setImageTag(String imageTag) {
        this.imageTag = imageTag;
    }

    public double getImageSize() {
        return imageSize;
    }

    public void setImageSize(double imageSize) {
        this.imageSize = imageSize;
    }

    public String checkLegality() {
        if (!StringUtils.isBlank(imageName) && !Project.isRegularDockerName(imageName)) {
            throw ApiException.wrapMessage(ResultStat.PARAM_ERROR, "image name not support, must match [a-z0-9]+([._-][a-z0-9]+)*");
        }
        if (!StringUtils.isBlank(imageTag) && !Project.isRegularDockerName(imageTag)) {
            throw ApiException.wrapMessage(ResultStat.PARAM_ERROR, "image tag not support , must match [a-z0-9]+([._-][a-z0-9]+)*");
        }
        registry = CommonUtil.domainUrl(registry);
        return null;
    }
}
